<?php

/**
 * content actions.
 *
 * @package    barilga
 * @subpackage content
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class contentOldActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $params = array();
    $params['type']       = $this->type = $request->getParameter('type');
    $params['categoryId'] = $this->categoryId = $request->getParameter('categoryId');
    $params['keyword']    = $this->keyword = $request->getParameter('keyword');
    $params['isFeatured'] = $this->isFeatured = $request->getParameter('isFeatured', 0);
    $params['isActive']   = $this->isActive = $request->getParameter('isActive', 'all');
    
    $this->pager = Doctrine::getTable('Content')->getPager($params, $request->getParameter('page'));
  }


  public function executeActive(sfWebRequest $request)
  {
    $this->forward404Unless($content = Doctrine::getTable('Content')->find($request->getParameter('id')));

    $content->setIsActive($request->getParameter('status'));
    $content->save();

    $this->getUser()->setFlash('success', 'Амжилттай хадгалагдлаа.', true);
    //$this->redirect('content/index?type='.$content->getType().'&categoryId='.$content->getCategoryId());
    $this->redirect($request->getReferer());
  }
  
  public function executeMakeOnhome(sfWebRequest $request)
  {
    $this->forward404Unless($content = Doctrine::getTable('Content')->find($request->getParameter('id')));

    $content->setIsOnhome($request->getParameter('status'));
    $content->save();

    $this->getUser()->setFlash('success', 'Амжилттай хадгалагдлаа.', true);
    //$this->redirect('content/index?type='.$content->getType().'&categoryId='.$content->getCategoryId());
    $this->redirect($request->getReferer());
  }

  public function executeFeatured(sfWebRequest $request)
  {
    $this->forward404Unless($content = Doctrine::getTable('Content')->find($request->getParameter('id')));

    $content->setIsFeatured($request->getParameter('status'));
    $content->save();

    $this->getUser()->setFlash('success', 'Амжилттай хадгалагдлаа.', true);
    //$this->redirect('content/index?type='.$content->getType().'&categoryId='.$content->getCategoryId());
    $this->redirect($request->getReferer());
  }


  public function executeDelete(sfWebRequest $request)
  {
    $this->forward404Unless($content = Doctrine::getTable('Content')->find(array($request->getParameter('id'))), sprintf('Object content does not exist (%s).', $request->getParameter('id')));

    $type = $content->getType();
    $categoryId = $content->getCategoryId();

    try {
      Doctrine::getTable('Image')->deleteByObject('content', $content->getId());
      $content->delete();
      $this->getUser()->setFlash('success', 'Амжилттай устлаа.', true);
    }catch (Exception  $e){}
    
    //$this->redirect('content/index?type='.$type.'&categoryId='.$categoryId);
    $this->redirect($request->getReferer());
  }

}